package days5.easy.title13;

/**
 * @Author fengzihao
 * @Date 2024-04-19 21:02
 */
class Solution {
    public int romanToInt(String s) {
        int count = 0;
        char[] temp = s.toCharArray();
        for (int i = 0; i < s.length()-1; i++) {
            if (getValue(temp[i])>=getValue(temp[i+1]))
                count+=getValue(temp[i]);
            else
                count-=getValue(temp[i]);
            ;
        }
        count+=getValue(temp[s.length()-1]);

        return count;
    }
    public static int getValue(char a){
        int number_num = 0;
        switch (a){
            case 'I':
                number_num = 1;
                break;
            case 'V':
                number_num = 5;
                break;
            case 'X':
                number_num = 10;
                break;
            case 'L':
                number_num = 50;
                break;
            case 'C':
                number_num = 100;
                break;
            case 'D':
                number_num = 500;
                break;
            case 'M':
                number_num = 1000;
                break;
            default:
                break;
        }
        return number_num;
    }
}
